// pages/personala/received/index.js
var Bmob = require('../../../utils/bmob.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [
      { "icon": "/images/heed.jpg", "word": "稀里哗啦", "price": "1元", "time": "2018-1-15 14:00", "amount": "1/10" },
      { "icon": "/images/heed.jpg", "word": "稀里哗啦", "price": "1元", "time": "2018-1-15 14:00", "amount": "1/10" },
      { "icon": "/images/heed.jpg", "word": "稀里哗啦", "price": "1元", "time": "2018-1-15 14:00", "amount": "1/10" },
      { "icon": "/images/heed.jpg", "word": "稀里哗啦", "price": "1元", "time": "2018-1-15 14:00", "amount": "1/10" },
      { "icon": "/images/heed.jpg", "word": "稀里哗啦", "price": "1元", "time": "2018-1-15 14:00", "amount": "1/10" },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var Diary = Bmob.Object.extend("receive");
    var query = new Bmob.Query(Diary);
    query.include("uid");
    query.include("eid");
    query.include("euid");


    var currentUser = Bmob.User.current();
    var objectId = currentUser.id;
    var post = Bmob.Object.createWithoutData("_User", objectId);
    query.equalTo("uid", post);
    var that = this;
    // 查询所有数据
    query.find({
      success: function (results) {
        that.setData({
          results: results
        })
        console.log("共查询到 " + results.length + " 条记录");
        // 循环处理查询到的数据
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          console.log(object.id + ' - ' + object.get('amount'));
        }
      },
      error: function (error) {
        console.log("查询失败: " + error.code + " " + error.message);
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})